<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑比对任务</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='layui/css/layui.css') }}">
</head>
<body>
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">任务名称</label>
    <div class="layui-input-block">
      <input type="text" hidden name="task_id" value="{{ data[0]['task_id'] }}">
      <input type="text" name="task_name" value="{{ data[0]['task_name'] }}" lay-verify="required" placeholder="请输入比对任务名称" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-inline">

      <label class="layui-form-label">数据源1</label>
      <div class="layui-input-inline">
        <select name="db_cfg_1_id" lay-verify="required" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_1_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

      <label class="layui-form-label">数据源2</label>
      <div class="layui-input-inline">
        <select name="db_cfg_2_id" lay-verify="required" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_2_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">数据源3</label>
      <div class="layui-input-inline">
        <select name="db_cfg_3_id" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_3_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

      <label class="layui-form-label">数据源4</label>
      <div class="layui-input-inline">
        <select name="db_cfg_4_id" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_4_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">数据源5</label>
      <div class="layui-input-inline">
        <select name="db_cfg_5_id" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_5_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

      <label class="layui-form-label">数据源6</label>
      <div class="layui-input-inline">
        <select name="db_cfg_6_id" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_6_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>

    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">数据源7</label>
      <div class="layui-input-inline">
        <select name="db_cfg_7_id" lay-search>
          <option value="">直接选择或搜索选择</option>
          {% for dbsource in dbsources %}
            {% if dbsource['db_cfg_id'] == data[0]['db_cfg_7_id'] %}
              <option value="{{ dbsource['db_cfg_id'] }}" selected>{{ dbsource['connect_name'] }}</option>
            {% else %}
              <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
            {% endif %}
          {% endfor %}
        </select>
      </div>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">描述或备注</label>
    <div class="layui-input-block">
      <textarea name="description" placeholder="请输入你想描述或备注的比对任务的相关信息(非必填)" class="layui-textarea"></textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
      <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
      <button type="button" class="layui-btn" onclick="closeWindow();">关闭</button>
    </div>
  </div>

</form>
</body>

<script src="{{ url_for('static', filename='js/jquery-3.6.0.min.js') }}"></script>
<script src="{{ url_for('static', filename='layui/layui.js') }}"></script>

<script>
layui.use(['form', 'laydate', 'util', 'layer'], function(){
  var form = layui.form;
  var layer = layui.layer;
  var laydate = layui.laydate;
  var util = layui.util;
  var layer = layui.layer

  // 提交事件
  form.on('submit(demo1)', function(data){
    var field = data.field; // 获取表单字段值
    // 此处可执行 Ajax 等操作
    var databaseSourceDataOfFormJson = JSON.stringify(field)
    // alert("databaseSourceDataOfForm = " + databaseSourceDataOfFormJson);
    $.ajax({
		url:'/editCompareTaskData',
		// type:'post',
		contentType:"json",
		data: { // 提交数据
               "databaseSourceDataOfForm": databaseSourceDataOfFormJson // 前者为字段名，后者为数据
        },
		success:function(data){
			if (data == "editCompareTaskData execute success") {
              layer.confirm('修改比对任务成功！', {
                btn: ['确定'] //按钮
              }, function(){
                // 或者直接操作DOM
                parent.layui.table.reload('ID-table-demo-search', {
                  url: '/getConfigCompareTaskData' // 重新从这个URL加载数据
                });
                // 关闭当前窗口
                var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index1); //再执行关闭

              });

            }
			// obj=JSON.parse(data);
		},
		error:function(){
			layer.alert('Ajax请求错误！', {
              icon: 5,
              shadeClose: true,
              title: 'ERROR'
            });
		}
	});

    return false; // 阻止默认 form 跳转
  });

});

function closeWindow(){
  var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  parent.layer.close(index1); //再执行关闭
}
</script>
</html>